package com.store.pet.petstore.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.squareup.picasso.Picasso;
import com.store.pet.petstore.R;
import com.store.pet.petstore.bean.OrderBean;

import java.util.List;

public class OrderAdapter extends BaseQuickAdapter<OrderBean.ContentBean.OrderListBean,BaseViewHolder> {

    int role = 0;

    public OrderAdapter(int layoutResId, @Nullable List<OrderBean.ContentBean.OrderListBean> data,int role) {
        super(layoutResId, data);
        this.role = role;
    }

    @Override
    protected void convert(BaseViewHolder helper, OrderBean.ContentBean.OrderListBean item) {
        ImageView imageView = helper.getView(R.id.order_item_petpic);
        if(!item.getPetpic().equals("")){
            Picasso.with(mContext).load(item.getPetpic()).into(imageView);
        }
        helper.setText(R.id.order_item_name,item.getPetname());  //宠物名
        helper.setText(R.id.order_item_price,"价格："+item.getPrice());  //价格
        helper.setText(R.id.order_item_time,"下单时间："+item.getCtime().replaceAll("T"," "));  //下单时间
        int status = item.getStatus();
        RelativeLayout rl = helper.getView(R.id.seller_function);
        LinearLayout ll = helper.getView(R.id.buyer_information);
        helper.addOnClickListener(R.id.order_item);  //点击订单查看详情
        if(role == 1) {
            //买家
            rl.setVisibility(View.GONE);
            ll.setVisibility(View.GONE);
            TextView tv1 = helper.getView(R.id.order_item_status);
            switch (status) {
                case 1:
                    tv1.setText("当前状态：已下单");
                    break;
                case 2:
                    tv1.setText("当前状态：已发货");
                    break;
                case 3:
                    tv1.setText("当前状态：已付款");
                    break;
            }
        }
        if(role == 2){
            //卖家
            TextView tv2 = helper.getView(R.id.ship); //发货
            TextView tv3 = helper.getView(R.id.determine);  //确认收货
            switch (status){
                case 1:
                    rl.setVisibility(View.VISIBLE);
                    tv2.setVisibility(View.VISIBLE);
                    tv3.setVisibility(View.GONE);
                    helper.addOnClickListener(R.id.ship);  //点击事件
                    break;
                case 2:
                    rl.setVisibility(View.VISIBLE);
                    tv3.setVisibility(View.VISIBLE);
                    tv2.setVisibility(View.GONE);
                    helper.addOnClickListener(R.id.determine);  //点击事件
                    break;
                case 3:
                    rl.setVisibility(View.GONE);  //订单完成后就没有此控件
                    break;
            }
            ll.setVisibility(View.VISIBLE);
            helper.setText(R.id.order_item_buyer_name,"买家："+item.getBuyername());
            helper.setText(R.id.order_item_buyer_phone,"买家电话："+item.getBuyerphone());
            helper.setText(R.id.order_item_buyer_address,"买家地址："+item.getAddress());
        }
    }
}
